package com.youyi.yyfilepickerlibrary.SDK;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import com.lkx.liandianqinew.R;
import com.youyi.yyfilepickerlibrary.SDK.YYPickSDK;
import com.youyi.yyfilepickerlibrary.core.FilePicker;
import com.youyi.yyfilepickerlibrary.core.model.EssFile;
import com.youyi.yyfilepickerlibrary.core.util.Const;
import com.youyi.yypermissionlibrary.SDK.OnPerListener;
import com.youyi.yypermissionlibrary.SDK.YYPerUtils;
import java.util.ArrayList;
import java.util.Iterator;

public class YYPickActivity extends AppCompatActivity {
    /* access modifiers changed from: protected */
    @Override // android.support.v7.app.AppCompatActivity, android.support.v4.app.SupportActivity, android.support.v4.app.FragmentActivity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        getWindow().addFlags(16);
        if (bundle == null) {
            resloveIntent(getIntent());
        }
    }

    /* access modifiers changed from: protected */
    @Override // android.support.v4.app.FragmentActivity
    public void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        resloveIntent(getIntent());
    }

    private void resloveIntent(final Intent intent) {
        YYPerUtils.initContext(this);
        YYPerUtils.sd(new OnPerListener() {
            /* class com.youyi.yyfilepickerlibrary.SDK.YYPickActivity.AnonymousClass1 */

            @Override // com.youyi.yypermissionlibrary.SDK.OnPerListener
            public void result(boolean z, String str) {
                if (z) {
                    YYPickActivity.this.judgeIntent(intent);
                    return;
                }
                if (YYPickSDK.mOnPickListener != null) {
                    YYPickSDK.mOnPickListener.result(false, "未申请权限!", null);
                    YYPickSDK.mOnPickListener = null;
                }
                YYPickActivity.this.finish();
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void judgeIntent(Intent intent) {
        String stringExtra = intent.getStringExtra("fileEndName");
        String[] stringArrayExtra = intent.getStringArrayExtra("fileEndNames");
        int intExtra = intent.getIntExtra("num", 1);
        boolean booleanExtra = intent.getBooleanExtra("isFoldType", false);
        String stringExtra2 = intent.getStringExtra("PicEnum");
        if (TextUtils.isEmpty(stringExtra2)) {
            stringExtra2 = YYPickSDK.PicEnum.file.toString();
        }
        int i = YYPickSDK.PicEnum.valueOf(stringExtra2).ordinal();
        if (i != 1) {
            if (i != 2) {
                if (i == 3) {
                    FilePicker.from(this).chooseForMimeType().setMaxCount(intExtra).setFileTypes("apk", "png", "jpg", "jpeg", "bmp", "txt", "pdf", "doc", "docx", "xls", "xlsx", "zip", "rar", "mp3", "wav", "wma", "mp4", "avi", "rmvb").requestCode(23).start();
                } else if (i == 4) {
                    FilePicker.from(this).chooseMedia().enabledCapture(true).setTheme(com.uuzuche.lib_zxing.R.style.AppTheme).requestCode(23).start();
                } else if (i == 5) {
                    FilePicker.from(this).chooseForBrowser().setMaxCount(1).isFolder(true).setFileTypes("folder").requestCode(24).start();
                }
            } else if (booleanExtra) {
                FilePicker.from(this).chooseForBrowser().setMaxCount(intExtra).setFileTypes(stringArrayExtra).requestCode(23).start();
            } else {
                FilePicker.from(this).chooseForMimeType().setMaxCount(intExtra).setFileTypes(stringArrayExtra).requestCode(23).start();
            }
        } else if (booleanExtra) {
            FilePicker.from(this).chooseForBrowser().setMaxCount(intExtra).setFileTypes(stringExtra).requestCode(23).start();
        } else {
            FilePicker.from(this).chooseForMimeType().setMaxCount(intExtra).setFileTypes(stringExtra).requestCode(23).start();
        }
    }

    /* access modifiers changed from: protected */
    @Override // android.support.v4.app.FragmentActivity
    public void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        if (i2 != -1) {
            finish();
            return;
        }
        if (i == 23) {
            ArrayList parcelableArrayListExtra = intent.getParcelableArrayListExtra(Const.EXTRA_RESULT_SELECTION);
            ArrayList arrayList = new ArrayList();
            if (parcelableArrayListExtra != null && parcelableArrayListExtra.size() > 0) {
                Iterator it = parcelableArrayListExtra.iterator();
                while (it.hasNext()) {
                    arrayList.add(((EssFile) it.next()).getAbsolutePath());
                }
            }
            if (YYPickSDK.mOnPickListener != null) {
                YYPickSDK.mOnPickListener.result(true, "", arrayList);
                YYPickSDK.mOnPickListener = null;
            }
        } else if (i == 24) {
            String stringExtra = intent.getStringExtra(Const.FOLDER_PATH);
            if (!TextUtils.isEmpty(stringExtra) && YYPickSDK.mOnFolderListener != null) {
                YYPickSDK.mOnFolderListener.result(true, "", stringExtra);
                YYPickSDK.mOnFolderListener = null;
            }
        }
        finish();
    }
}
